package com.dhcc.DRGsHosp.web.controller;

import java.text.ParseException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.openkoala.koala.commons.InvokeResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dhcc.DRGsHosp.facade.ForeCastFacade;
import com.dhcc.DRGsHosp.facade.ForeCastFacade2;
import com.dhcc.DRGsHosp.facade.dto.IndexCalDTO;
import com.dhcc.DRGsHosp.infra.util.DrgsIndex;
import com.dhcc.DRGsHosp.infra.util.GlobalData;
import org.codehaus.jackson.map.ObjectMapper;

/**
 * @title		:ForeCastController.java
 * @description	:
 * @author		:lileizheng
 * @date		:2015年6月8日
 * @version     :1.0
 * @copyright   :DHCC 2013-2014 
 */
@Controller("drgsHospWebController19")
@RequestMapping("/ForeCast")
public class ForeCastController {

	@Autowired
	private ForeCastFacade foreCastFacade;
	
	@Autowired
	private ForeCastFacade2 foreCastFacade2;
	
	/**
	 *  hospForeCast.  
	 *  @Description：获取科室组的调整参数
	 *  @Author LiuHongjun
	 *  @param dto
	 *  @return 
	 *  @Date:2017年10月24日下午2:24:10
	 */
	@ResponseBody
	@RequestMapping(value = "/findDepGroupForeCast", method = RequestMethod.POST)
	public InvokeResult findDepGroupForeCast(String dateFrom,String dateTo,String forecastYear,String monitorType){
		List<Map<String, Object>> depGroupList = foreCastFacade.findDepGroupForeCast( dateFrom, dateTo, forecastYear, monitorType);
		return InvokeResult.success(depGroupList);
	}
	/**
	 * 
	 *  quotasComputer.  
	 *  @Description：医保测算开始
	 *  @Author LiuHongjun
	 *  @param dto
	 *  @return 
	 *  @Date:2017年10月18日上午8:58:52
	 */
	@ResponseBody
	@RequestMapping(value = "/quotasComputer", method = RequestMethod.POST)
	public InvokeResult quotasComputer(String adjustParameter,String dateFrom,String dateTo,String forecastYear,String hospCode, String monitorType){
		GlobalData.cookie = new ConcurrentHashMap<String, Object>();
		return foreCastFacade.quotasComputer(adjustParameter, dateFrom, dateTo, forecastYear,hospCode, monitorType);
	}
	/**
	 * 
	 *  @Discription：保存科室调整参数
	 *  @Author： liuhongjun
	 *  @param dto
	 *  @return
	 *  @Date:2018年3月14日下午4:33:53
	 */
	@ResponseBody
	@RequestMapping(value = "/saveParamDepData", method = RequestMethod.POST)
	public InvokeResult saveParamDepData(String adjustParameter,String dateFrom,String dateTo,String forecastYear){
		return foreCastFacade.saveParamDepData(adjustParameter, dateFrom, dateTo, forecastYear);
	}
	
	@ResponseBody
	@RequestMapping(value = "/getProcess", method = RequestMethod.POST)
	public InvokeResult getProcess(IndexCalDTO dto){
		return InvokeResult.success(GlobalData.cookie);
	}
	/**
	 * 
	 *  loadDepParam.  
	 *  @Description：获取科室调整参数
	 *  @Author LiuHongjun
	 *  @param dto
	 *  @return 
	 *  @Date:2017年10月24日下午4:02:06
	 */
	@ResponseBody
	@RequestMapping(value = "/loadDepParam", method = RequestMethod.POST)
	public InvokeResult loadDepParam(String pardepgroupCode,String dateFrom,String dateTo,String forecastYear){
		List<Map<String, Object>> list=foreCastFacade.loadDepParam( pardepgroupCode, dateFrom, dateTo, forecastYear);
		return InvokeResult.success(list);
	}
	
	@ResponseBody
	@RequestMapping(value = "/loadDepDisParam", method = RequestMethod.POST)
	public InvokeResult loadDepDisParam(IndexCalDTO dto){
		return foreCastFacade.loadDepDisParam(dto);
	}
	
	@ResponseBody
	@RequestMapping(value = "/saveParamDepDisData", method = RequestMethod.POST)
	public InvokeResult saveParamDepDisData(IndexCalDTO dto){
		return foreCastFacade.saveParamDepDisData(dto);
	}
	
	@ResponseBody
	@RequestMapping(value = "/getHospData", method = RequestMethod.POST)
	public InvokeResult getHospData(IndexCalDTO dto){
		return foreCastFacade.getHospData(dto);
	}
	
	@ResponseBody
	@RequestMapping(value = "/saveParamDepGroupDisData", method = RequestMethod.POST)
	public InvokeResult saveParamDepGroupDisData(IndexCalDTO dto){
		return foreCastFacade.saveParamDepGroupDisData(dto);
	}
	/**
	 *  saveExpected.  
	 *  @Description：保存测算数据
	 *  @Author LiuHongjun
	 *  @param dto
	 *  @return 
	 * @throws ParseException 
	 *  @Date:2017年10月18日上午11:50:42
	 */
	@ResponseBody
	@RequestMapping(value = "/saveExpected", method = RequestMethod.POST)
	public InvokeResult saveExpected(String quotaStr,String saveType,String type ,String forecastYear,String dateFrom,String dateTo) throws ParseException{
		return foreCastFacade.saveExpected(quotaStr, saveType, type,forecastYear,dateFrom ,dateTo);
	}
	/**
	 * 
	 *  getLastResultHosp.  
	 *  @Description：获取上次医院测算数据
	 *  @Author LiuHongjun
	 *  @param saveType
	 *  @return 
	 *  @Date:2017年10月19日下午7:00:54
	 */
	@ResponseBody
	@RequestMapping(value = "/getLastResultHosp", method = RequestMethod.POST)
	public InvokeResult getLastResultHosp(String saveType,String stdYear,String dateFrom,String dateTo){
		return foreCastFacade.getLastResultHosp(saveType,stdYear,DrgsIndex.getRoleCode(),dateFrom,dateTo);
	}
	/**
	 * 
	 *  getLastResultDepGroup.  
	 *  @Description：获取上次科室组数据
	 *  @Author LiuHongjun
	 *  @param saveType
	 *  @return 
	 *  @Date:2017年10月19日下午7:01:40
	 */
	@ResponseBody
	@RequestMapping(value = "/getLastResultDepGroup", method = RequestMethod.POST)
	public InvokeResult getLastResultDepGroup(String saveType,String stdYear,String dateFrom,String dateTo){
		return foreCastFacade.getLastResultDepGroup(saveType,stdYear,DrgsIndex.getRoleCode(),dateFrom,dateTo);
	}
	/**
	 * 
	 *  getLastResultDep.  
	 *  @Description：获取上次科室数据
	 *  @Author LiuHongjun
	 *  @param saveType
	 *  @return 
	 *  @Date:2017年10月19日下午7:01:57
	 */
	@ResponseBody
	@RequestMapping(value = "/getLastResultDep", method = RequestMethod.POST)
	public InvokeResult getLastResultDep(String saveType,String stdYear,String dateFrom,String dateTo){
		return foreCastFacade.getLastResultDep(saveType,stdYear,DrgsIndex.getRoleCode(),dateFrom,dateTo);
	}
	
	@ResponseBody
	@RequestMapping(value = "/getLastResultMDC", method = RequestMethod.POST)
	public InvokeResult getLastResultMDC(IndexCalDTO dto){
		return foreCastFacade2.getLastResultMDC(dto);
	}
	
	@ResponseBody
	@RequestMapping(value = "/getLastResultADRG", method = RequestMethod.POST)
	public InvokeResult getLastResultADRG(IndexCalDTO dto){
		return foreCastFacade2.getLastResultADRG(dto);
	}
	
	@ResponseBody
	@RequestMapping(value = "/getLastResultDRG", method = RequestMethod.POST)
	public InvokeResult getLastResultDRG(IndexCalDTO dto){
		return foreCastFacade2.getLastResultDRG(dto);
	}
	
	@ResponseBody
	@RequestMapping(value = "/getNewPlan", method = RequestMethod.POST)
	public InvokeResult getNewPlan(String depCode, String addYear){
		return foreCastFacade.getNewPlan(depCode, addYear);
	}
	
	@ResponseBody
	@RequestMapping(value = "/savePlan", method = RequestMethod.POST)
	public InvokeResult savePlan(String param){
		ObjectMapper objectMapper = new ObjectMapper();
		Map<String, Object> json;
		try {
			json = objectMapper.readValue(param, Map.class);
		} catch (Exception e) {
			e.printStackTrace();
			json = new HashMap<String, Object>();
		} 
		return foreCastFacade.savePlan(json);
	}
	
	@ResponseBody
	@RequestMapping(value = "/delPlan", method = RequestMethod.POST)
	public InvokeResult delPlan(String depCode, String addYear){
		return foreCastFacade.delPlan(depCode, addYear);
	}
	
	@ResponseBody
	@RequestMapping(value = "/getNewPlanDRGs", method = RequestMethod.POST)
	public InvokeResult getNewPlanDRGs(String depCode, String addYear){
		return foreCastFacade.getNewPlanDRGs(depCode, addYear);
	}
	
	@ResponseBody
	@RequestMapping(value = "/saveNewPlanDRGs", method = RequestMethod.POST)
	public InvokeResult saveNewPlanDRGs(String param, String depCode, String addYear){
		ObjectMapper objectMapper = new ObjectMapper();
		List<Map<String, Object>> json;
		try {
			json = objectMapper.readValue(param, LinkedList.class);
		} catch (Exception e) {
			e.printStackTrace();
			json = new LinkedList<Map<String, Object>>();
		} 
		return foreCastFacade.saveNewPlanDRGs(json, depCode, addYear);
	}
	
	@ResponseBody
	@RequestMapping(value = "/changeYear")
	public InvokeResult changeYear(String year){
		return foreCastFacade.changeYear(year);
	}
	/**
	 *  saveToQuotamanage.  
	 *  @Description：保存为绩效标杆
	 *  @Author LiuHongjun
	 *  @return 
	 *  @Date:2017年10月18日下午4:49:31
	 */
	@ResponseBody
	@RequestMapping(value = "/saveToQuotamanage")
	public InvokeResult saveToQuotamanage(String stdType,String saveType,String forecastYear){
		return foreCastFacade.saveToQuotamanage(stdType,saveType,forecastYear,DrgsIndex.getRoleCode());
	}
}
